package org.example.ffmmx.bmapandroid;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import com.baidu.mapapi.SDKInitializer;

public class MainActivity extends ActionBarActivity {
    Button drawCircleBtn,markerPoiBtn,myLocationBtn,loginBtn,demoBtn;
    MainActivityButtonOnClickHandler buttonClickListener;


    class MainActivityButtonOnClickHandler implements View.OnClickListener {
        @Override
        public void onClick(View v) {
             if(v.getId() == R.id.drawCircleBtn) {
                 Intent intent=new Intent(getApplicationContext(),DrawCircleDemo.class);
                 startActivity(intent);
             }
            else if (v.getId() == R.id.markPoiBtn) {
                 Intent intent=new Intent(getApplicationContext(),MarkerPoiDemo.class);
                 startActivity(intent);
            }
            else if (v.getId() == R.id.locBtn) {
                Intent intent=new Intent(getApplicationContext(),LocationDemo.class);
                 startActivity(intent);
            }
            else if (v.getId() == R.id.loginBtn) {
                Intent intent=new Intent(getApplicationContext(),LoginActivity.class);
                 startActivity(intent);
            }
            else if(v.getId() == R.id.demoBtn){
                 Intent intent=new Intent(getApplicationContext(),DemoLoginActivity.class);
                 startActivity(intent);
             }
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        SDKInitializer.initialize(getApplicationContext());
        setContentView(R.layout.activity_main);

        drawCircleBtn= (Button) findViewById(R.id.drawCircleBtn);
        markerPoiBtn= (Button) findViewById(R.id.markPoiBtn);

        buttonClickListener=new MainActivityButtonOnClickHandler();
        drawCircleBtn.setOnClickListener(buttonClickListener);
        markerPoiBtn.setOnClickListener(buttonClickListener);
        myLocationBtn= (Button) findViewById(R.id.locBtn);
        myLocationBtn.setOnClickListener(buttonClickListener);

        loginBtn= (Button) findViewById(R.id.loginBtn);
        loginBtn.setOnClickListener(buttonClickListener);

        demoBtn= (Button) findViewById(R.id.demoBtn);
        demoBtn.setOnClickListener(buttonClickListener);

//        //定义多边形的五个顶点
//        LatLng pt1 = new LatLng(39.93923, 116.357428);
//        LatLng pt2 = new LatLng(39.91923, 116.327428);
//        LatLng pt3 = new LatLng(39.89923, 116.347428);
//        LatLng pt4 = new LatLng(39.89923, 116.367428);
//        LatLng pt5 = new LatLng(39.91923, 116.387428);
//        List<LatLng> pts = new ArrayList<LatLng>();
//        pts.add(pt1);
//        pts.add(pt2);
//        pts.add(pt3);
//        pts.add(pt4);
//        pts.add(pt5);
////构建用户绘制多边形的Option对象
//        OverlayOptions polygonOption = new PolygonOptions()
//                .points(pts)
//                .stroke(new Stroke(5, 0xAA00FF00))
//                .fillColor(0xAAFFFF00);
////在地图上添加多边形Option，用于显示
//        map.addOverlay(polygonOption);


    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    /**
     * Dispatch onResume() to fragments.  Note that for better inter-operation
     * with older versions of the platform, at the point of this call the
     * fragments attached to the activity are <em>not</em> resumed.  This means
     * that in some cases the previous state may still be saved, not allowing
     * fragment transactions that modify the state.  To correctly interact
     * with fragments in their proper state, you should instead override
     * {@link #onResumeFragments()}.
     */
    @Override
    protected void onResume() {
        super.onResume();
    }

    /**
     * Dispatch onPause() to fragments.
     */
    @Override
    protected void onPause() {
        super.onPause();
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}
